RAIS  3.2
C:/Projekte/RAIS/common/RADEVSearchClasses/RADEVRowComparer.cs
Go to the documentation of this file.
00001 using System;
00002 using System.Collections.Generic;
00003 using System.Text;
00004 
00005 namespace RAIS.Common.RADEVSearchClasses
00006 {
00007     public class RADEVRowComparer : IComparer<RADEVRow>
00008     {
00009         private bool _isInvert;
00010         private string _method;
00011 
00012         public RADEVRowComparer(string method, bool isInvert)
00013         {
00014             _method = method;
00015             _isInvert = isInvert;
00016         }
00017 
00018         #region IComparer<JobStats> Members
00019 
00020         public int Compare(RADEVRow x, RADEVRow y)
00021         {
00022             int result = 0;
00023             switch (_method)
00024             {
00025                 case "EventID":
00026                     string[] xArray = x.EventID.Split('-');
00027                     string[] yArray = y.EventID.Split('-');
00028                     if(xArray.Length!=yArray.Length)
00029                         result=string.Compare(x.EventID, y.EventID);
00030 
00031                     int xPart;
00032                     int yPart;
00033                     for(int i=0;i<xArray.Length;i++)
00034                     {
00035                         if (!int.TryParse(xArray[i], out xPart) || !int.TryParse(yArray[i], out yPart))
00036                         {
00037                             result = string.Compare(xArray[i], yArray[i]);
00038                             if (result != 0) break;
00039                         }
00040                         else if (xPart != yPart)
00041                         {
00042                             result = xPart > yPart ? 1 : -1;
00043                             break;
00044                         }
00045                     }
00046                     break;
00047                 case "FacilitiName":
00048                     result = string.Compare(x.FacilitiName, y.FacilitiName);
00049                     break;
00050                 case "EventDate":
00051                     result = string.Compare(x.EventDate, y.EventDate);
00052                     break;
00053                 case "Radiotionsource":
00054                     result = string.Compare(x.Radiotionsource, y.Radiotionsource);
00055                     break;
00056                 case "SpecificPractice":
00057                     result = string.Compare(x.SpecificPractice, y.SpecificPractice);
00058                     break;
00059                 case "ReportStatus":
00060                     result = string.Compare(x.ReportStatus, y.ReportStatus);
00061                     break;
00062             }
00063             return _isInvert ? result : -result;
00064         }
00065 
00066         #endregion        
00067     }
00068 }